/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package logging;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import logging.report.Logger;
import logging.report.Record;
import logging.report.scribe.ScribeLogger;

/**
 *
 * @author Salm
 */
public class Logging implements Logger {
    private final Logger logger;

    private Logging(Logger logger) {
        this.logger = logger;
    }
    
    private static final Logging inst;

    static
    {
        Logger _logger = new ScribeLogger();
        inst = new Logging(_logger);
    }
    
    private static Logger noTargetLogger()
    {
        return new Logger() {

            @Override
            public void writeLog(Record record) {
            }

            @Override
            public void writeLogs(List<Record> records) {
            }
        };
    }
    
    @Override
    public void writeLog(Record record) {
        logger.writeLog(record);
    }

    @Override
    public void writeLogs(List<Record> records) {
        logger.writeLogs(records);
    }
    
    public static void log(Record record)
    {
        inst.writeLog(record);
    }
    
    public static void log(Collection<Record> records)
    {
        inst.writeLogs(toList(records));
    }
    
    public static void log(Record... records)
    {
        inst.writeLogs(Arrays.asList(records));
    }
    
    private static List<Record> toList(Collection<Record> records)
    {
        if (records instanceof List)
        {
            return (List) records;
        }
        
        return new ArrayList<Record>();
    }
}
